package com.nineclock.attendance.controller;

import com.nineclock.attendance.dto.AttendPunchDTO;
import com.nineclock.attendance.dto.AttendPunchUserWholeDayDTO;
import com.nineclock.attendance.service.AttendPunchService;
import com.nineclock.common.entity.Result;
import com.nineclock.system.AttendPunchControllerApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping
public class AttendPunchController implements AttendPunchControllerApi {

    @Autowired
    AttendPunchService attendPunchService;


    @Override
    @PostMapping("/punch")
    public Result punch(@RequestBody AttendPunchDTO attendPunchDTO) {
        attendPunchService.punch(attendPunchDTO);
        return Result.success();
    }

    @Override
    @GetMapping("/get")
    public Result<AttendPunchUserWholeDayDTO> queryPunchRecord() {
        AttendPunchUserWholeDayDTO wholeDayDTO= attendPunchService.queryPunchRecord();
        return Result.success(wholeDayDTO);
    }

    @Override
    @GetMapping("/members")
    public Result<List<AttendPunchDTO>> queryMembers(
            @RequestParam(value = "startTime")String startTime,
            @RequestParam(value = "endTime")String endTime) {
        List<AttendPunchDTO> attendPunchDtoS=attendPunchService.queryMembers(startTime,endTime);
        return Result.success(attendPunchDtoS);
    }

    @Override
    @GetMapping("/export")
    public void exportAttendData(String startTime, String endTime) throws IOException {
        attendPunchService.exportAttendData(startTime,endTime);
    }
}
